package com.yj.wisemoms.Disk;

import com.yj.wisemoms.Util.Util;

import android.content.Context;
import android.content.SharedPreferences;

public class SaveData {
	
	Context mContext;
	SharedPreferences SaveData;
	
	private static SaveData uniqueInstance;  
	
	private SaveData(Context mContext) {
		
		SaveData = mContext.getSharedPreferences("wisemoms",mContext.MODE_PRIVATE);
	}  
	
	public static SaveData getInstance(Context mContext){  
		if(uniqueInstance == null){  			
			uniqueInstance = new SaveData(mContext);  
		}  
		return uniqueInstance;  
	} 

	
	public void save(String Key,int Value){
		
		SharedPreferences.Editor editor = SaveData.edit();
		editor.putInt(Key, Value);
		editor.commit();
	}
	
	public void save(String Key,String Value){
		
		SharedPreferences.Editor editor = SaveData.edit();
		editor.putString(Key, Value);
		editor.commit();
	}
	
	public void SetRecently(String num){
		
		String temp = SaveData.getString("recent", null);
		boolean dupnum = false;
		
		if(temp == null){
			temp = num;
		}else{
			String[] temparr = temp.split(",");
			for(String str : temparr){
				if(str.equals(num)){
					dupnum = true;
				}
			}
			
			if(!dupnum){
				num = ","+num;
				temp += num;
			}
		}
		
		SharedPreferences.Editor editor = SaveData.edit();
		editor.putString("recent", temp);
		editor.commit();
		
	}
	
	public int getInt(String Key){
		return SaveData.getInt(Key, 0);
	}
	
	public String getString(String Key){
		return SaveData.getString(Key, "0");
	}
	
	public String getRecently(){
		return  SaveData.getString("recent", null);
	}
	
	public void ClearRecently(){
		String temp = null;
		SharedPreferences.Editor editor = SaveData.edit();
		editor.putString("recent", temp);
		editor.commit();
	}
	
}
